import 'package:flutter/material.dart';

/// 雷达图轴基础配置
class RadarAxis {
  RadarAxis(
      {this.lineColor = Colors.grey,
      this.lineWidth = 1,
      this.lineDash,
      this.labelCount = 5,
      this.labelTextSize = 12,
      this.labelTextDecSize = 14,
      this.labelTextDecFontWeight = FontWeight.w600,
      this.labelColor = Colors.black,
      this.labelDecColor = Colors.black,
      this.labelOffsetAxis = 0,
      this.valueFormatter,
      this.valueDesFormatter})
      : assert(lineWidth > 0, "line width must than 0"),
        assert(labelCount >= 0, "line count must than or equal 0");

  /// 轴线颜色
  final Color lineColor;

  /// 轴线宽度
  final double lineWidth;

  /// 绘制虚线时，指定虚实之间的长度。设置此值则轴线为虚线，否则为实线。
  final List<double>? lineDash;

  /// 轴标签数量
  final int labelCount;

  /// 标签文本大小
  final double labelTextSize;

  /// 标签颜色
  final Color labelColor;

  /// 标签Dec文本大小
  final double labelTextDecSize;

  /// 标签Dec文本字重
  final FontWeight labelTextDecFontWeight;

  /// 标签Dex颜色
  final Color labelDecColor;

  /// 标签与轴线的偏移值
  final double labelOffsetAxis;

  /// 轴线文本格式化器
  final AxisValueFormatter? valueFormatter;

  /// 文本格式化器，目前暂时只针对xAxis
  final AxisValueFormatter? valueDesFormatter;
}

/// 格式化轴上指定位置标签
typedef AxisValueFormatter = String Function(int position);

/// 雷达图X轴配置
class RadarXAxis extends RadarAxis {
  RadarXAxis(
      {super.lineColor,
      super.lineWidth,
      super.lineDash,
      super.labelCount,
      super.labelTextSize,
      super.labelColor,
      super.labelOffsetAxis,
      super.valueFormatter,
      super.valueDesFormatter,
      this.lineStartOffset = 0,
      this.lineEndPadding = 0,
      this.angleErrorRange = 10})
      : assert(lineStartOffset >= 0),
        assert(angleErrorRange >= 0),
        assert(labelCount >= 3);

  /// 轴线绘制起始偏移值
  final double lineStartOffset;

  /// 轴线结束位置padding，如果此值大于0，则[YAxis]和内容则往里缩进
  final double lineEndPadding;

  /// 当轴线角度为90°或270°时，轴线标签将根据轴线水平居中绘制。此属性将指定90°或270°左右误差范围，在此范围内的角度都认为是90°或270°。
  /// 比如误差范围时10°，那么80°~110°都按照90°规则绘制轴线标签，270°同理
  final double angleErrorRange;
}

/// 雷达图Y轴配置
class RadarYAxis extends RadarAxis {
  RadarYAxis(
      {super.lineColor,
      super.lineWidth,
      super.lineDash,
      super.labelCount = 6,
      super.labelTextSize,
      super.labelColor,
      super.labelOffsetAxis,
      super.valueFormatter,
      this.lineDrawConfig,
      this.lineDashConfig,
      this.drawLabel = false,
      this.labelDrawStartAngle = -30,
      this.min = 0,
      this.step = 20,
      this.lineStyle = LineStyle.liner});

  /// 配置轴线是否绘制
  final LineDrawConfig? lineDrawConfig;

  /// 配置轴线是否绘制成虚线，配置此值后[lineDash]无效
  final LineDashConfig? lineDashConfig;

  /// 是否绘制轴标签
  final bool drawLabel;

  /// 轴标签绘制起始角度
  final double labelDrawStartAngle;

  /// 轴最小值
  final double min;

  /// 绘制坐标每个网格间隔值
  final double step;

  /// 轴线的样式
  final LineStyle lineStyle;

  /// 绘制坐标最大值
  double get max {
    if (labelCount <= 0) {
      return 0;
    }
    return min + (labelCount - 1) * step;
  }
}

/// 轴线的样式
enum LineStyle { liner, circle }

typedef LineDrawConfig = bool Function(int position);

typedef LineDashConfig = List<double>? Function(int position);
